#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
struct person{
    int id;
    string piao;
    person(int a, string s) : id(a), piao(s) {
    }
};
bool compare(person& a, person& b) {
    if(a.piao.size() != b.piao.size()) return a.piao.size() > b.piao.size();
    int n = a.piao.size();
    for(int i = 0; i < n; i++) {
        if(a.piao[i] != b.piao[i]) {
            return a.piao[i] > b.piao[i];
        }
    }
    return true;
    
}
int main() {
    int n;
    cin >> n;
    vector<person> a;
    for(int i = 1; i <= n; i++) {
        string temp;
        cin >> temp;
        a.push_back(person(i, temp));
    }
    sort(a.begin(), a.end(), compare);
    cout << a[0].id << endl;
    cout << a[0].piao << endl;
    return 0;
}